﻿using System;
using System.Text;
using System.Collections;
using ValueHelper.Infrastructure;
using System.Collections.Generic;

namespace SedionFormDesigner.Serializer.BasicStruct
{
    public class XmlFormModel : IEnumerable
    {
        public Int32 MaxHeight = 0;
        public Int32 Width = 575;
        public Int32 Height = 790;
        public Int32 Top = 0;

        private String formTemplate = "<div class='form_page' style='position:absolute; width:{0}px; height:{1}px; top:{2}px;'>{3}</div>";

        KeyvalList<String, ElementModel> keyvalList;

        public XmlFormModel()
        {
            keyvalList = new KeyvalList<string, ElementModel>();
        }

        public Int32 Count { get { return keyvalList.Count; } }

        public void Add(String key, ElementModel value)
        {
            this.keyvalList.Add(key, value);
        }
        public void AddRange(List<Keyval<string, ElementModel>> list)
        {
            this.keyvalList.AddRange(list);
        }
        public ElementModel this[String name]
        {
            get { return keyvalList[name]; }
            set { keyvalList[name] = value; }
        }

        public Keyval<String, ElementModel> this[Int32 index]
        {
            get { return keyvalList[index]; }
            set { keyvalList[index] = value; }
        }

        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();
            foreach (Keyval<String, ElementModel> keyval in keyvalList)
            {
                builder.Append(keyval.Value);
            }

            return String.Format(formTemplate, Width, Height, Top, builder.ToString());
        }

        #region IEnumerable 成员

        public IEnumerator GetEnumerator()
        {
            return keyvalList.GetEnumerator();
        }

        #endregion
    }
}
